home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / utility / freedos.zip / COM050.ZIP / EXEC.C < prev    next >
C/C++ Source or Header  |  1996-01-17  |  1KB  |  60 lines

  1. /*
  2.  *  EXEC.C - external program execution
  3.  *
  4.  *
  5.  *
  6.  *  Comments:
  7.  *
  8.  *  ?????? (Steffen Kaiser) -----------------------------------------------
  9.  *    started.
  10.  *
  11.  *  12/??/95 (Svante Frey) ------------------------------------------------
  12.  *    reorganized code
  13.  *
  14.  *  1/6/96 (Tim Norman) ---------------------------------------------------
  15.  *    added this history
  16.  *
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <dos.h>
  21. #include <string.h>
  22.  
  23. typedef unsigned char byte;
  24. typedef unsigned word;
  25.  
  26. /* align one byte */
  27. #pragma option -a-
  28.    struct ExecBlock {
  29.       word segOfEnv;
  30.       char far*cmdLine;
  31.       struct fcb far*fcb1, far*fcb2;
  32.    };
  33. /* default alignment */
  34. #pragma option -a.
  35.  
  36. int lowLevelExec(char far *cmd, struct ExecBlock far *bl);
  37.  
  38. int exec(const char *cmd, char *cmdLine, const unsigned segOfEnv)
  39. {   
  40.    unsigned char buf[128];
  41.    struct fcb fcb1, fcb2;
  42.    struct ExecBlock execBlock;
  43.  
  44.    /* generate Pascal string from the command line */
  45.    memcpy(&buf[1], cmdLine, buf[0] = strlen(cmdLine));
  46.    memcpy(&buf[1] + buf[0], "\xd", 2);
  47.    
  48.    /* fill execute structure */
  49.    execBlock.segOfEnv = segOfEnv;
  50.    execBlock.cmdLine = (char far*)buf;
  51.    execBlock.fcb1 = (struct fcb far*)&fcb1;
  52.    execBlock.fcb2 = (struct fcb far*)&fcb2;
  53.    
  54.    /* fill FCBs */
  55.    if((cmdLine = parsfnm(cmdLine, &fcb1, 1)) != NULL)
  56.       parsfnm(cmdLine, &fcb2, 1);
  57.  
  58.    return lowLevelExec(cmd, &execBlock);
  59. }
  60.